package org.example.day06;

import java.io.*;

import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import org.example.day06.util.GlobalUtil;

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=UTF-8");
        //获取系统时间，并且转化成格式化时间字符串响应给前端
        String timeStr=GlobalUtil.getTimeStr(System.currentTimeMillis());
        //响应数据
        response.getWriter().write(timeStr);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        doGet(req, resp);
    }
}